<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>The source code</title>
  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  <style type="text/css">
    .highlight { display: block; background-color: #ddd; }
  </style>
  <script type="text/javascript">
    function highlight() {
      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
    }
  </script>
</head>
<body onload="prettyPrint(); highlight();">
  <pre class="prettyprint lang-js">&lt;?php
<span id='global-property-'>/**
</span> * Cube PHP Framework
 * 
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the &quot;License&quot;); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 * 
 * @author Dillen / Steffen
 */

namespace Library\Mvc;
 
<span id='Library-Mvc-Request'>/**
</span> * @class Library.Mvc.Request 
 *
 * Request
 */
class Request
{
<span id='Library-Mvc-Request-property-requestUri'>	/**
</span>	 * @property {String} requestUri
	 * @var string
	 */
	public $requestUri;
	
<span id='Library-Mvc-Request-property-controller'>	/**
</span>	 * @property {String} controller
	 * @var string
	 */
	public $controller;
	
<span id='Library-Mvc-Request-property-action'>	/**
</span>	 * @property {String} action
	 * @var string
	 */
	public $action;
	
<span id='Library-Mvc-Request-property-parameters'>	/**
</span>	 * @property {Array} parameters
	 * @var array
	 */
	public $parameters = array();
	
<span id='Library-Mvc-Request-method-__construct'>	/**
</span>	 * Constructor
	 * 
	 * @method __construct
	 * @param {String} [$request=null] Request string, example: controller/action/argument
	 */
	public function __construct($request = null)
	{
		$this-&gt;requestUri = $this-&gt;_cleanUri(($request == null) ? $this-&gt;_fetchUri($request) : $request);
		
		$parts = explode('/', $this-&gt;requestUri);
		
		$this-&gt;controller = array_shift($parts);
		$this-&gt;action = array_shift($parts);
		$this-&gt;parameters = (array)$parts;
	}
	
<span id='Library-Mvc-Request-method-_cleanUri'>	/**
</span>	 * Clean Uri
	 * 
	 * @method _cleanUri
	 * @private
	 * @param {String} $uri
	 * @return {String}
	 */
	private function _cleanUri($uri)
	{
		return parse_url(trim(urldecode($uri), '/'), PHP_URL_PATH);
	}
	
<span id='Library-Mvc-Request-method-_fetchUri'>	/**
</span>	 * Fetch the request uri
	 * 
	 * @method _fetchUri
	 * @private
	 * @return {String}
	 */
	private function _fetchUri()
	{
		// Check if PATH_INFO is available
		$uri = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO');
		if ($uri != '' &amp;&amp; $uri != '/')
		{
			return $uri;
		}

		// Pick the REQUEST_URI as last resort
		$uri = $_SERVER['REQUEST_URI'];
		if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0)
		{
			$uri = substr($uri, strlen($_SERVER['SCRIPT_NAME']));
		}
		else if (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0)
		{
			$uri = substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME'])));
		}
		
		// Fix the $_GET vars
		$parts = explode('?', $uri, 2);
		$uri = $parts['0'];

		return $uri;
	}
	
<span id='Library-Mvc-Request-method-__toString'>	/**
</span>	 * @method __toString
	 * @return string
	 */
	public function __toString()
	{
		return (string)$this-&gt;requestUri;
	}
}</pre>
</body>
</html>
